package org.example.qst.filter;

import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class PicCountFilter extends OncePerRequestFilter {

    private int count = 0;

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//        System.out.println("---------=======---------");
//        System.out.println("Request Filter" + request.getRequestURI());
//        System.out.println("---------=======---------");
        if (request.getRequestURI().contains("/statics")) {
            System.out.println("---------=======------------------=======---------");
            System.out.println("该请求正在访问静态资源" + request.getRequestURI());
            count++;
            System.out.println("静态资源被访问次数为:" + count);
            System.out.println("---------=======------------------=======---------");
        }

        //放行
        filterChain.doFilter(request,response);
    }
}
